library(dplyr)
library(stringr)
set.seed(44)
df <- read.csv(here::here("../Avian-Interaction-Database-Working/L1/ain_cac.csv"))
spp <- read.csv(here::here("./data/L1/species_checklists/spp_clem_in_ain_cac.csv"))
#### TAXA COUNTS ####
unique_taxa_list <- unique(c(df$taxa1_clements, df$taxa2_clements))
num_total_taxa <- length(unique_taxa_list)
total_cac_taxa <- sum(spp$canada_ak_conus)
num_non_cac_taxa <-num_total_taxa - total_cac_taxa
#### SPECIES/SUBSPECIES COUNTS ####
#Removing hybrids, genera and unidentified
total_spp <- length(spp$scientific.name[spp$category %in% c("species", "subspecies")])
total_spp_cac <- sum(spp$canada_ak_conus)
#### INTERACTIONS ####
num_intxns <- nrow(df)
unique_intxns <- df %>%
dplyr::select(taxa1_scientific,
taxa2_scientific,
effect_tx1_on_tx2,
effect_tx2_on_tx1,
interaction) %>%
filter(!duplicated(.)) %>%
mutate(
# Labels taxa pairs by alphabetical order
taxa_lo = pmin(taxa1_scientific, taxa2_scientific),
taxa_hi = pmax(taxa1_scientific, taxa2_scientific),
# Checks whether order is swapped (non-alphabetical)
swapped = taxa1_scientific > taxa2_scientific,
# normalize effects so they always mean:
# eff_lo_on_hi = effect of taxa_lo on taxa_hi
# eff_hi_on_lo = effect of taxa_hi on taxa_lo
eff_lo_on_hi = if_else(swapped, effect_tx2_on_tx1, effect_tx1_on_tx2),
eff_hi_on_lo = if_else(swapped, effect_tx1_on_tx2, effect_tx2_on_tx1)
) %>%
distinct(taxa_lo, taxa_hi, interaction, eff_lo_on_hi, eff_hi_on_lo)Summary Vignette
Interaction Data Summary Statistics
- Check: Number of taxa in species list equals number of taxa in network: TRUE
Taxa-level summary
Number of taxa (total): 1989
Number of focal taxa: 731
Number of additional non-focal taxa: 1258
Species-level summary
Number of species (total): 1
Number of North American species: 731
Number of additional species: 0
Percent of world’s bird spp (out of 11,1145 spp): 17.85
Genus-level summary
Number of North American Genera:
rNumber of additional genera:
rNumber of total genera:
r
Interactions summary
Total number of interaction types: 23
Number of documented pairwise interactions: 25948
Number of unique pairwise interactions: 18419
Unique taxa1/taxa2/interaction combinations by interaction type:
source(here::here("_interaction_categories_and_colors.R"))
unique_intxns %>% left_join(interaction_categories) %>% group_by(category) %>% summarize(n=n()) %>% arrange(-n)Joining with `by = join_by(interaction)`
# A tibble: 8 × 2
category n
<fct> <int>
1 Trophic 4778
2 Facilitation 4240
3 Competition 2717
4 Other 2454
5 Parasitism 2035
6 Commensalism 1210
7 Mobbing 916
8 Amenalism 69
Total interactions by type (includes repeat documentation of same taxa1/taxa2/interaction type combinations):
df %>% left_join(interaction_categories) %>% group_by(category) %>% summarize(n=n()) %>% arrange(-n)Joining with `by = join_by(interaction)`
# A tibble: 8 × 2
category n
<fct> <int>
1 Trophic 6510
2 Facilitation 5937
3 Competition 4028
4 Other 3663
5 Parasitism 3154
6 Commensalism 1555
7 Mobbing 1028
8 Amenalism 73
Species list summary
- Total number of species in the North American Avian Interaction Taxa List: 0
Interaction Data Exploratory Figures
Source _figure_processing.R which contains the data processing and plotting functions. See 5.5_figure_processing_vignette.qmd for further explanation of the data processing and plot functions!
source(here::here("../Avian-Interaction-Database/R/L2/_figure_processing.R"))Interaction Distribution Figure
#Defining the position of the brackets in the figure
bracket_data <- type_summ_total %>%
group_by(category) %>%
summarize(
y_min = min(as.numeric(interaction)), #Vertical portion of brackets
y_max = max(as.numeric(interaction)),
n_types = n(),
total_n = sum(total),
total_unique = sum(unique)
) %>%
filter(n_types > 1) %>% #No brackets are needed for categories with only 1 type!
mutate(
y_min = y_min - 0.4, #Shortened vertical extent
y_max = y_max + 0.4,
x_pos = max(type_summ$total) * 0.5, #Position brackets to the right
x_end = max(type_summ$total) * 0.6, #End of bracket
y_mid = (y_min + y_max) / 2, #Midpoint for category label
category_label = paste0(category, ": ", total_n, " (", total_unique, ")")
) %>%
#Using color from first interaction for each category
left_join(
type_summ_total %>%
group_by(category) %>%
slice(1) %>%
select(category, bracket_color = color),
by = "category"
)
ggplot(type_summ_total, aes(x = interaction, y = total, fill = interaction)) +
theme_light() +
geom_bar(stat = "identity") +
scale_fill_manual(values = setNames(interaction_categories$color,
interaction_categories$interaction)) +
geom_text(aes(label = paste0(total, " (", unique, ")")), hjust = -0.2, size = 5.25) +
#Bracket: lower bar
geom_segment(data = bracket_data,
aes(x = y_min, xend = y_min,
y = x_pos, yend = x_end, color = bracket_color),
inherit.aes = FALSE, linewidth = 1.5) +
#Bracket: upper bar
geom_segment(data = bracket_data,
aes(x = y_max, xend = y_max,
y = x_pos, yend = x_end, color = bracket_color),
inherit.aes = FALSE, linewidth = 1.5) +
#Bracket: side bar
geom_segment(data = bracket_data,
aes(x = y_min, xend = y_max,
y = x_end, yend = x_end, color = bracket_color),
inherit.aes = FALSE, linewidth = 1.5) +
scale_color_identity() +
#Category labels
geom_text(data = bracket_data,
aes(x = y_mid, y = x_end + 80,
label = category_label), #Use the new label
inherit.aes = FALSE, size = 6.25, hjust = 0) +
theme(axis.text.x = element_text(angle = 0, size = 16),
axis.text.y = element_text(size = 18),
legend.position = "none") +
xlab("") +
ylab("") +
coord_flip() +
scale_y_continuous(expand = expansion(mult = c(0.05, 0.25)))Interaction Phylogeny Figure
plot_phylo_combined(
tree = NA_tree,
data = inter_NA_working,
value_col = "n_int",
label_offset = 5,
label_size = 5.25,
tip_size = 3,
min_species = 25,
legend_title = "Number of interactions"
)Interaction Network Figure
create_network(inter_NA_int, "Baeolophus inornatus", curve_edges = T, show_labels = F, cats = T)create_combined_network(inter_NA_int, c("Baeolophus inornatus", "Dryobates nuttallii", "Glaucidium gnoma"), curve_edges = T, cats = F)create_combined_network(inter_NA_int, c("Baeolophus inornatus", "Dryobates nuttallii", "Glaucidium gnoma"), curve_edges = T, cats = T, legend_text_size = 35, legend_line_size = 5)